package net.jumpengine.util;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javafx.scene.image.Image;
import net.jumpengine.Manager;

public class UIO {
	private UIO() {}
	
	public static String filePath(String path) {
		URL url = UIO.class.getResource(path);
		return url.getFile();
	}
	
	public static List<Image> loadImages(String dict){
		String path=filePath(dict);
		File f=new File(path);
		if(!f.isDirectory()) {
			Manager.getLog().error("UIO[loadToIcons]path:", dict,"不是目录!");
			return null;
		}
		List<Image> list=new ArrayList<>();
		for(File k:f.listFiles()) {
			list.add(new Image("file:"+k.getAbsolutePath())) ;
		}
		return list;
	}
	
	public static Image loadImage(String file){
		String path=filePath(file);
		File f=new File(path);
		if(!f.exists()) {
			Manager.getLog().error("UIO[loadToImage]file:'%s'不存在", file);
			return null;
		}
		return new Image("file:"+f.getAbsolutePath());
	}
}
